package com.bdbit.ChargingStation.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 *
 */
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "mqtt")
public class MqttProperties {
    private String brokerUrl = "tcp://8.148.4.179:1883";
    private String username = "admin";
    private String password = "zxcvbnm";
    private String clientId = "charging_station_server";

    private int keepAliveInterval = 60;
    private boolean automaticReconnect = true;
    private boolean cleanSession = true;

    // 直接使用完整的主题字符串
    //private String devicePublishTopic = "89860455021980028344";   // 设备发布主题
    //private String deviceSubscribeTopic = "861877077967114"; // 服务端发布主题
    private String devicePublishTopic = "";   // 设备发布主题
    private String deviceSubscribeTopic = ""; // 服务端发布主题

    @PostConstruct
    public void validateConfig() {
        log.info("MQTT配置验证:");
        log.info("  Broker URL: {}", brokerUrl);
        log.info("  Client ID: {}", clientId);
//        log.info("  Device Publish Topic: {}", devicePublishTopic);
//        log.info("  Device Subscribe Topic: {}", deviceSubscribeTopic);

//        if (devicePublishTopic == null || devicePublishTopic.isEmpty()) {
//            throw new IllegalStateException("mqtt.device-publish-topic 未配置");
//        }
//
//        if (deviceSubscribeTopic == null || deviceSubscribeTopic.isEmpty()) {
//            throw new IllegalStateException("mqtt.device-subscribe-topic 未配置");
//        }
    }

    // Getters and Setters
    public String getBrokerUrl() {
        return brokerUrl;
    }

    public void setBrokerUrl(String brokerUrl) {
        this.brokerUrl = brokerUrl;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getDevicePublishTopic() {
        return devicePublishTopic;
    }

    public void setDevicePublishTopic(String devicePublishTopic) {
        this.devicePublishTopic = devicePublishTopic;
    }

    public String getDeviceSubscribeTopic() {
        return deviceSubscribeTopic;
    }

    public void setDeviceSubscribeTopic(String deviceSubscribeTopic) {
        this.deviceSubscribeTopic = deviceSubscribeTopic;
    }

    public int getKeepAliveInterval() {
        return keepAliveInterval;
    }

    public void setKeepAliveInterval(int keepAliveInterval) {
        this.keepAliveInterval = keepAliveInterval;
    }

    public boolean isAutomaticReconnect() {
        return automaticReconnect;
    }

    public void setAutomaticReconnect(boolean automaticReconnect) {
        this.automaticReconnect = automaticReconnect;
    }

    public boolean isCleanSession() {
        return cleanSession;
    }

    public void setCleanSession(boolean cleanSession) {
        this.cleanSession = cleanSession;
    }
}